﻿using Dapper.DBContext;
using Guoc.BigMall.Admin.Services;
using Guoc.BigMall.Application;
using Guoc.BigMall.Application.DTO;
using Guoc.BigMall.Application.Search;
using Guoc.BigMall.Application.ViewObject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Guoc.BigMall.Admin.Controllers
{
    [Permission]
    public class DistributeController : Controller
    {
        IContextFacade _context;
        IDBContext _db;
        IDistributeFacade _distributeFacade;
        public DistributeController(IContextFacade context, IDBContext db, IRoleFacade roleFacade, IDistributeFacade distributeFacade)
        {
            this._context = context;
            this._db = db;
            this._distributeFacade = distributeFacade;
        }
        public ActionResult Index()
        {
            return View();
        }

        public JsonResult LoadData(Pager page, SearchDistribute search)
        {
            var rows = _distributeFacade.GetList(page, search);
            return Json(new { success = true, data = rows, total = page.Total, JsonRequestBehavior.AllowGet });
        }

        /// <summary>
        /// 查询商品明细
        /// </summary>
        /// <param name="id">商品id productId</param>
        /// <returns></returns>
        public JsonResult detail(int id)
        {
            var model = _distributeFacade.GetById(id);
            return Json(new { success = true, data = model });
        }

        [HttpPost]
        public JsonResult Save(DistributeModel model) {

            _distributeFacade.Save(model);
            return Json(new { success = true });
        }

    }
}